package cn.com.sparkle.paxos.model;

import java.io.Serializable;

public class Id implements Serializable, Comparable<Id> {
	private static final long serialVersionUID = 1L;
	private long increaseId = 0;
	private String address = "";

	public Id(long increaseId, String address) {
		super();
		this.increaseId = increaseId;
		this.address = address;
	}

	@Override
	public int compareTo(Id o) {
		if (increaseId == o.increaseId) {
			int result = address.compareTo(o.address);
			if (result == 0)
				return 0;
			else
				return result > 0 ? 1 : -1;
		}
		return increaseId > o.increaseId ? 1 : -1;
	}

	@Override
	public boolean equals(Object obj) {
		return compareTo((Id) obj) == 0;
	}

	@Override
	public int hashCode() {
		return (int) increaseId + address.hashCode();
	}

	public long getIncreaseId() {
		return increaseId;
	}

	public String getAddress() {
		return address;
	}

	public void setIncreaseId(long increaseId) {
		this.increaseId = increaseId;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String toString() {
		return this.increaseId + "-" + address;
	}
}
